const { src, dest, series, parallel, watch } = require('gulp');
const { cleanTemp }  = require('./clean');
const { lint, lintStyles, lintScripts } = require('./lint');
const { compile, compileHtml, compileStyles, compileScripts } = require('./compile');
const browserSync = require('browser-sync').create();

function copyImages() {
    return src('src/assets/images/**')
        .pipe(dest('temp/assets/images/'))
}

function copyFonts() {
    return src('src/assets/fonts/**')
        .pipe(dest('temp/assets/fonts/'))
}

function copyPublic() {
    return src('public/**')
        .pipe(dest('temp/'))
}

function serve() {

    browserSync.init({
        server: "temp"
    });
    
    watch(['src/**/*.html'], compileHtml);
    watch(['src/**/*.scss'], series(
        lintStyles,
        compileStyles
    ));
    watch(['src/**/*.js'], series(
        lintScripts,
        compileScripts
    ));
    watch(['src/**'], function(cb) {
        browserSync.reload()
        cb()
    });
}

module.exports = series(
    cleanTemp,
    parallel(copyImages, copyFonts, copyPublic),
    lint,
    compile,
    serve
)
